home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / lang_ext / vbawk / multigre.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-08-12  |  11.4 KB  |  391 lines

  1. VERSION 2.00
  2. Begin Form MultiGrep 
  3.    BorderStyle     =   3  'Fixed Double
  4.    Caption         =   "Multi-Grep"
  5.    ClientHeight    =   4935
  6.    ClientLeft      =   1695
  7.    ClientTop       =   2085
  8.    ClientWidth     =   5820
  9.    Height          =   5625
  10.    Left            =   1635
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    ScaleHeight     =   4935
  14.    ScaleWidth      =   5820
  15.    Top             =   1455
  16.    Width           =   5940
  17.    Begin CheckBox CaseSensitive 
  18.       Caption         =   "Case sensitive?"
  19.       Height          =   375
  20.       Left            =   900
  21.       TabIndex        =   14
  22.       TabStop         =   0   'False
  23.       Top             =   4380
  24.       Width           =   1815
  25.    End
  26.    Begin CommandButton ClearAllBtn 
  27.       Caption         =   "Clear All Search/Replace Strings"
  28.       Height          =   315
  29.       Left            =   180
  30.       TabIndex        =   13
  31.       TabStop         =   0   'False
  32.       Top             =   3840
  33.       Width           =   5475
  34.    End
  35.    Begin CommandButton ReplaceBtn 
  36.       Caption         =   "&Replace list item"
  37.       Height          =   375
  38.       Left            =   3180
  39.       TabIndex        =   12
  40.       Top             =   960
  41.       Width           =   2475
  42.    End
  43.    Begin CommandButton AddBtn 
  44.       Caption         =   "&Add to list"
  45.       Default         =   -1  'True
  46.       Height          =   375
  47.       Left            =   180
  48.       TabIndex        =   2
  49.       Top             =   960
  50.       Width           =   2475
  51.    End
  52.    Begin TextBox Text1 
  53.       Height          =   285
  54.       Index           =   0
  55.       Left            =   1440
  56.       TabIndex        =   0
  57.       Top             =   240
  58.       Width           =   4275
  59.    End
  60.    Begin TextBox Text1 
  61.       Height          =   285
  62.       Index           =   1
  63.       Left            =   1440
  64.       TabIndex        =   1
  65.       Top             =   600
  66.       Width           =   4275
  67.    End
  68.    Begin Frame Frame1 
  69.       Caption         =   "Search/Replace Strings:"
  70.       Height          =   2835
  71.       Left            =   120
  72.       TabIndex        =   7
  73.       Top             =   1440
  74.       Width           =   5595
  75.       Begin ListBox List2 
  76.          Height          =   1590
  77.          Left            =   3000
  78.          TabIndex        =   3
  79.          TabStop         =   0   'False
  80.          Top             =   360
  81.          Width           =   2535
  82.       End
  83.       Begin CommandButton DeleteBtn 
  84.          Caption         =   "&Delete Search/Replace String"
  85.          Height          =   315
  86.          Left            =   60
  87.          TabIndex        =   9
  88.          TabStop         =   0   'False
  89.          Top             =   2040
  90.          Width           =   5475
  91.       End
  92.       Begin ListBox List1 
  93.          Height          =   1590
  94.          Left            =   60
  95.          TabIndex        =   8
  96.          TabStop         =   0   'False
  97.          Top             =   360
  98.          Width           =   2535
  99.       End
  100.       Begin Label Label2 
  101.          Alignment       =   2  'Center
  102.          Caption         =   "="
  103.          Height          =   255
  104.          Left            =   2640
  105.          TabIndex        =   11
  106.          Top             =   960
  107.          Width           =   315
  108.       End
  109.    End
  110.    Begin CommandButton CancelBtn 
  111.       Cancel          =   -1  'True
  112.       Caption         =   "&Cancel"
  113.       Height          =   375
  114.       Left            =   4620
  115.       TabIndex        =   6
  116.       TabStop         =   0   'False
  117.       Top             =   4380
  118.       Width           =   1095
  119.    End
  120.    Begin CommandButton GoButton 
  121.       Caption         =   "&Go"
  122.       Height          =   375
  123.       Left            =   3360
  124.       TabIndex        =   5
  125.       TabStop         =   0   'False
  126.       Top             =   4380
  127.       Width           =   1095
  128.    End
  129.    Begin Label Label1 
  130.       Caption         =   "Search For:"
  131.       Height          =   255
  132.       Index           =   0
  133.       Left            =   120
  134.       TabIndex        =   4
  135.       Top             =   240
  136.       Width           =   1215
  137.    End
  138.    Begin Label Label1 
  139.       Caption         =   "Replace With:"
  140.       Height          =   255
  141.       Index           =   1
  142.       Left            =   120
  143.       TabIndex        =   10
  144.       Top             =   600
  145.       Width           =   1335
  146.    End
  147.    Begin Menu ID_FILE 
  148.       Caption         =   "File"
  149.       Begin Menu ID_FILE_OPEN 
  150.          Caption         =   "Open"
  151.       End
  152.       Begin Menu ID_FILE_SAVE 
  153.          Caption         =   "Save"
  154.       End
  155.       Begin Menu ID_FILE_SAVEAS 
  156.          Caption         =   "Save As"
  157.       End
  158.       Begin Menu sep1 
  159.          Caption         =   "-"
  160.       End
  161.       Begin Menu ID_FILE_EXIT 
  162.          Caption         =   "Exit"
  163.       End
  164.    End
  165. Dim RetrievedFileName As String
  166. Const DEFAULT_DATA_FILE = "c:\multigre.def"
  167. Sub AddBtn_Click ()
  168.     If Text1(0).Text = "" Then
  169.         Text1(0).SetFocus
  170.     Else
  171.         If FoundAlready((Text1(0).Text)) >= 0 Then
  172.             MsgBox "Search string already exists, can't add to list.", 0, APPNAME
  173.         Else
  174.             List1.AddItem (Text1(0).Text)
  175.             List2.AddItem (Text1(1).Text)
  176.             List1.ListIndex = List1.ListCount - 1
  177.             List2.ListIndex = List2.ListCount - 1
  178.             Text1(0).SetFocus
  179.             Text1(0).Text = ""
  180.             Text1(1).Text = ""
  181.         End If
  182.     End If
  183. End Sub
  184. Sub CancelBtn_Click ()
  185.     Tag = "Cancel"
  186.     Hide
  187. End Sub
  188. Sub ClearAllBtn_Click ()
  189.     List1.Clear
  190.     List2.Clear
  191.     RefreshTextBoxes
  192. End Sub
  193. Sub DeleteBtn_Click ()
  194.     DeleteFromListBoxes
  195.     RefreshTextBoxes
  196. End Sub
  197. Sub DeleteFromListBoxes ()
  198.     If List1.ListIndex = -1 Then
  199.         Exit Sub
  200.     End If
  201.     If List1.ListIndex = List1.ListCount - 1 Then
  202.         NewListIndex% = List1.ListCount - 2
  203.     Else
  204.         NewListIndex% = List1.ListIndex
  205.     End If
  206.     List1.RemoveItem List1.ListIndex
  207.     List2.RemoveItem List2.ListIndex
  208.     List1.ListIndex = NewListIndex%
  209.     List2.ListIndex = NewListIndex%
  210. End Sub
  211. Sub Form_Activate ()
  212.     RefreshTextBoxes
  213. End Sub
  214. Sub Form_Load ()
  215.     On Error Resume Next
  216.     If FileExists(DEFAULT_DATA_FILE) Then
  217.         RestoreListBoxes (DEFAULT_DATA_FILE)
  218.         List1.ListIndex = 0
  219.         List2.ListIndex = 0
  220.     End If
  221. End Sub
  222. Function FoundAlready (Target As String) As Integer
  223.     For i% = 0 To (List1.ListCount - 1)
  224.         If List1.List(i%) = Target Then
  225.             FoundAlready = i%
  226.             Exit Function
  227.         End If
  228.     Next i%
  229.     FoundAlready = -1
  230. End Function
  231. Sub GoButton_Click ()
  232.     SaveListBoxes (DEFAULT_DATA_FILE)
  233.     If CaseSensitive.Value = 0 Then
  234.         COMPAREMODE = COMPARE_CASEINSENSITIVE
  235.     End If
  236.     For i% = 0 To (List1.ListCount - 1)
  237.         SearchStr(i%) = List1.List(i%)
  238.         RepStr(i%) = List2.List(i%)
  239.     Next i%
  240.     NumStrings = List1.ListCount
  241.     Tag = "Go"
  242.     Hide
  243. End Sub
  244. Sub ID_FILE_EXIT_Click ()
  245.     End
  246. End Sub
  247. Sub ID_FILE_OPEN_Click ()
  248.     On Error GoTo Cancelled
  249.     FileSave.CMDialog1.CancelError = True
  250.     FileSave.CMDialog1.DefaultExt = ".mtg"
  251.     FileSave.CMDialog1.Filter = "Data Files|*.mtg"
  252.     FileSave.CMDialog1.Action = 1
  253.     RetrievedFileName = FileSave.CMDialog1.Filename
  254.     RestoreListBoxes (RetrievedFileName)
  255.     List1.ListIndex = 0
  256.     List2.ListIndex = 0
  257.     RefreshTextBoxes
  258.     Exit Sub
  259. Cancelled:
  260.     Exit Sub
  261. End Sub
  262. Sub ID_FILE_SAVE_Click ()
  263.     If RetrievedFileName = "" Then
  264.         On Error GoTo ByeBye
  265.         FileSave.CMDialog1.CancelError = True
  266.         FileSave.CMDialog1.Action = 2
  267.         SaveListBoxes (FileSave.CMDialog1.Filename)
  268.     Else
  269.         SaveListBoxes RetrievedFileName
  270.     End If
  271.     Exit Sub
  272. ByeBye:
  273.     Exit Sub
  274. End Sub
  275. Sub ID_FILE_SAVEAS_Click ()
  276.     On Error GoTo Quit
  277.     FileSave.CMDialog1.CancelError = True
  278.     FileSave.CMDialog1.DefaultExt = ".mtg"
  279.     FileSave.CMDialog1.Filter = "Data Files|*.mtg"
  280.     FileSave.CMDialog1.Action = 2
  281.     SaveListBoxes (FileSave.CMDialog1.Filename)
  282.     Exit Sub
  283. Quit:
  284.     Exit Sub
  285. End Sub
  286. Sub List1_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  287.     On Error Resume Next
  288.     List2.ListIndex = List1.ListIndex
  289.     RefreshTextBoxes
  290. End Sub
  291. Sub List1_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  292.     On Error Resume Next
  293.     List2.ListIndex = List1.ListIndex
  294. End Sub
  295. Sub List2_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  296.     List1.ListIndex = List2.ListIndex
  297.     RefreshTextBoxes
  298. End Sub
  299. Sub List2_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  300.     List1.ListIndex = List2.ListIndex
  301. End Sub
  302. Sub RefreshTextBoxes ()
  303.     RefreshTextBoxes2
  304.     Text1(0).SetFocus
  305. End Sub
  306. Sub RefreshTextBoxes2 ()
  307.     If List1.ListIndex = -1 Then
  308.         Text1(0).Text = ""
  309.         Text1(1).Text = ""
  310.     End If
  311.     Text1(0).Text = List1.List(List1.ListIndex)
  312.     Text1(1).Text = List2.List(List2.ListIndex)
  313. End Sub
  314. Sub ReplaceBtn_Click ()
  315.     If Text1(0).Text = "" Then
  316.         Text1(0).SetFocus
  317.     Else
  318.         If List1.ListIndex = -1 Then
  319.             MsgBox "No search/replace string selected, can't replace.", 0, APPNAME
  320.             Exit Sub
  321.         End If
  322.         If List1.ListIndex = List1.ListCount - 1 Then
  323.             'Special case, last one in list
  324.             DeleteFromListBoxes
  325.             List1.AddItem (Text1(0).Text)   'add at end
  326.             List2.AddItem (Text1(1).Text)   'add at end
  327.             List1.ListIndex = List1.ListCount - 1
  328.             List2.ListIndex = List2.ListCount - 1
  329.         Else
  330.             DeleteFromListBoxes
  331.             List1.AddItem (Text1(0).Text), List1.ListIndex
  332.             List2.AddItem (Text1(1).Text), List2.ListIndex
  333.         End If
  334.         RefreshTextBoxes
  335.     End If
  336. End Sub
  337. Sub RestoreListBoxes (TheFile As String)
  338.     List1.Clear
  339.     List2.Clear
  340.     RefreshTextBoxes2
  341.     On Error GoTo BadOpn
  342.     FileNum% = FreeFile
  343.     Open TheFile For Input As #FileNum%
  344.     On Error GoTo Finished
  345.     While 1
  346.         Line Input #FileNum%, Temp$
  347.         List1.List(i%) = Temp$
  348.         Line Input #FileNum%, Temp$
  349.         List2.List(i%) = Temp$
  350.         i% = i% + 1
  351.     Wend
  352. BadOpn:
  353.     MsgBox "Error: " & Error$ & " opening file " & TheFile, 0, APPNAME
  354.     Exit Sub
  355. Finished:
  356.     Close #FileNum%
  357.     If List1.ListCount <> List2.ListCount Then
  358.         MsgBox "Invalid data file; number of search strings not same as number of replace strings.", 0, APPNAME
  359.     End If
  360.     Exit Sub
  361. End Sub
  362. Sub SaveListBoxes (TheFile As String)
  363.     On Error GoTo BadOpen
  364.     FileNum% = FreeFile
  365.     Open TheFile For Output As #FileNum%
  366.     On Error GoTo BadWrite
  367.     For i% = 0 To (List1.ListCount - 1)
  368.         Print #FileNum%, List1.List(i%)
  369.         Print #FileNum%, List2.List(i%)
  370.     Next i%
  371.     Close #FileNum%
  372.     Exit Sub
  373. BadOpen:
  374.     MsgBox "Error: " & Error$ & " opening file " & TheFile, 0, APPNAME
  375.     Exit Sub
  376. BadWrite:
  377.     MsgBox "Error: " & Error$ & " accessing file " & TheFile, 0, APPNAME
  378.     Exit Sub
  379. End Sub
  380. Sub Text1_LostFocus (Index As Integer)
  381.     On Error Resume Next
  382.     If Index = 0 Then
  383.         WhereFound% = FoundAlready((Text1(0).Text))
  384.         If WhereFound% >= 0 Then
  385.             List1.ListIndex = WhereFound%
  386.             List2.ListIndex = WhereFound%
  387.             RefreshTextBoxes2
  388.         End If
  389.     End If
  390. End Sub
  391.